#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__

#include <iostream>
#include <string>
#include <unistd.h>

class Channel
{
public:
    Channel(int wfd, pid_t id)
        :_wfd(wfd)
        ,_who(id)
    {
        _name = "channel-" + to_string(wfd) + "-" + to_string(id);
    }
    ~Channel()
    {}

    string Name()
    {
        return _name;
    }

    void Send(int cmd)
    {
        write(_wfd, &cmd, sizeof(cmd));
    }

    void Close()
    {
        close(_wfd);
    }

    pid_t GetId()
    {
        return _who;
    }

    int Wfd()
    {
        return _wfd;
    }

private:
    int _wfd;
    string _name;
    pid_t _who;
};

#endif